# Maintainer: Florian Pritz <bluewind@xinu.at>
# Contributor: Geoffroy Carrier <geoffroy.carrier@koon.fr>
# Contributor: Daniel J Griffiths <ghost1227@archlinux.us>

pkgname=vimpager
pkgver=2.06
pkgrel=6
pkgdesc="A vim-based script to use as a PAGER."
arch=('any')
url="https://www.vim.org/scripts/script.php?script_id=1723"
license=('custom:BSD')
depends=('vim')
makedepends=('sharutils')
noextract=(vimpager-$pkgver.tar.gz)
backup=(etc/vimpagerrc)
source=("vimpager-$pkgver.tar.gz::https://github.com/rkitover/vimpager/tarball/$pkgver"
        "https://github.com/rkitover/vimpager/releases/download/$pkgver/man.tar.gz")
md5sums=('2b0986775fd98c10c3f8536fa6bd6890'
         'ab371844f9fbe9ae28a9baba061924bc')
sha256sums=('ae824388315a7decf4265a24560494eb38692aae08edf18d237d7ac347bc3f1d'
            '9aad1e1dd3546ce64626627f4684fdef04f0ca9d40a4815d84e6ef8ceacc6cdf')

prepare() {
	cd "${srcdir}"

	mkdir -p "$srcdir/vimpager-$pkgver"
	bsdtar --strip-components=1 -C "$srcdir/vimpager-$pkgver" -xf vimpager-$pkgver.tar.gz

	cd "$srcdir/vimpager-$pkgver"

	sed -i "s/\r$//" vimpager
	cp "$srcdir/"{vimpager.1,vimcat.1} .

	# FS#52042; can be removed in 2.07
	sed -i '/hi/{s/ctermbg=none/ctermbg=NONE/;s/guibg=none/guibg=NONE/; s/cterm=none/cterm=NONE/; s/gui=none/gui=NONE/;}' ansiesc/autoload/AnsiEsc.vim 
}

build() {
	cd "${srcdir}/vimpager-$pkgver"
	make vimpager
}

package() {
	cd "${srcdir}/vimpager-$pkgver"

	make SYSCONFDIR="/etc" PREFIX="/usr" DESTDIR="$pkgdir" install

	install -Dm644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/license.txt"
}
